package com.faceCaptor.util;

import java.text.SimpleDateFormat;
import java.util.Date;


public class DateUtil {

    private static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:ss";
    private static final String SHORT_FORMAT = "yyyy-MM-dd";
    public static Long getMillisTime(){
        return System.currentTimeMillis();
    }

    public static String getDate(){
    	SimpleDateFormat format = new SimpleDateFormat(SHORT_FORMAT);
        return format.format(new Date(getMillisTime()));
    }
    public static String getDateTime(){
        SimpleDateFormat format = new SimpleDateFormat(STANDARD_FORMAT);
        return format.format(new Date(getMillisTime()));
    }

    public static String millisToDate(String millisTime){

        SimpleDateFormat format = new SimpleDateFormat(STANDARD_FORMAT);
        return format.format(new Date(Long.valueOf(millisTime)));
    }

    public static Integer dateGetHour(String date){
        String[] dateArr = date.split(" ");
        String[] timeArr = dateArr[1].split(":");
        return Integer.valueOf(timeArr[0]);
    }

    public static Integer dateGetHour(Long millisTime){
        String date = millisToDate(String.valueOf(millisTime));
        return dateGetHour(date);
    }

    public static Integer wechatTimeGetHour(String wechatTime){
        String date = millisToDate(String.valueOf(wechatTime+"000"));
        return dateGetHour(date);
    }

    public static Boolean isProvideTime(String wechatTime,Integer startTime,Integer endTime){
        int nowHour = wechatTimeGetHour(wechatTime);
        if (nowHour>=startTime&&nowHour<endTime){
            return true;
        }else {
            return false;
        }
    }

//    @Test
    public static void main(String args[]){
        System.out.println(millisToDate("1529482739000"));
        System.out.println(dateGetHour(Long.valueOf("1529473966796")));
        System.out.println(wechatTimeGetHour("1529482739"));
        System.out.println(isProvideTime("1529482739",16,17));
    }
}
